package timbap.visualizer.impl.logging;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

public class BriefLogFormatter extends Formatter {

	private static final DateFormat format = new SimpleDateFormat("hh:mm:ss");
	private static final String lineSep = System.getProperty("line.separator");

    public String format(LogRecord record) {
		String loggerName = record.getLoggerName();
        if(loggerName == null) {
			loggerName = "root";
		}
        String simpleClassName = loggerName.substring(loggerName.lastIndexOf(".") + 1);
        StringBuilder output = new StringBuilder()
			.append("[")
			.append(record.getLevel()).append('|')
			.append(Thread.currentThread().getName()).append('|')
			.append(format.format(new Date(record.getMillis())))
			.append("]")
            .append(simpleClassName)
            .append(": ")
            .append(record.getMessage()).append(' ')
			.append(lineSep);
		return output.toString();
	}

}
